﻿// ***********************************************************************
// Assembly         : MVC4Portal
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="_WebAPIControllers_Base.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using InnovaApp.Portals.MVC4Portal.Models.JSonModels;
using InnovaApp.Portals.MVC4Portal.Models.WebAPIModels.JSTO;
using INNOVACALL.Framework.Common;

namespace InnovaApp.Portals.MVC4Portal.Controllers.WebAPIControllers
{
    /// <summary>
    /// _layout.js scripts that can to be executed after a treatment
    /// </summary>
    public enum enScriptToExecute{
        /// <summary>
        /// Displays a JQueryUI dialog box IFrame
        /// </summary>
        [StringValue("$.fn.jqDialogAlert(r.messageTitle,r.message,'');")]
        DisplayMessage,
        /// <summary>
        /// Displays a JQueryUI dialog box with dynamic IFrame
        /// </summary>
        [StringValue("$.fn.jqDialogAjaxError = function (r.messageTitle, r.message, r.redirectionUrl, r.width, r.height);")]
        DisplayIFrameMessage
    }

    /// <summary>
    /// Class _WebAPIControllers_Base
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class _WebAPIControllers_Base<T> : ApiController, IWebAPIJSonResult<T> where T : _JSTO_Base
    {
        /// <summary>
        /// Gets or sets the API data.
        /// </summary>
        /// <value>The API data.</value>
        public T ApiData { get; set; }

        /// <summary>
        /// Creates the response.
        /// </summary>
        /// <param name="statusCode">The status code.</param>
        /// <returns>HttpResponseMessage.</returns>
        public HttpResponseMessage CreateResponse(HttpStatusCode statusCode) {
            HttpResponseMessage toReturn;
            toReturn = Request.CreateResponse<T>(statusCode, ApiData);
            return toReturn;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="_WebAPIControllers_Base{T}"/> class.
        /// </summary>
        public _WebAPIControllers_Base()
        {
            ApiData = Activator.CreateInstance<T>();
        }

    }
}